{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "39b2b0fe",
   "metadata": {},
   "source": [
    "## Using an Iterable\n",
    "\n",
    "You can pass a slice of an iterable returned by one electron as an input to another iterable in a lattice.\n",
    "\n",
    "### Prerequisites\n",
    "\n",
    "Create two electrons, one that returns an iterable and one that takes an iterable as an input."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "314ca0c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import covalent as ct\n",
    "\n",
    "@ct.electron\n",
    "def task_1():\n",
    "    return ['a', 'b', 'c', 'd', 'e']\n",
    "    \n",
    "@ct.electron\n",
    "def task_2(items):\n",
    "    items.reverse()\n",
    "    return(items)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97416355",
   "metadata": {},
   "source": [
    "### Procedure\n",
    "\n",
    "Pass the first electron's iterable output to the second electron."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "89f7d540",
   "metadata": {},
   "outputs": [],
   "source": [
    "@ct.lattice\n",
    "def workflow(**params):\n",
    "    res_1 = task_1()\n",
    "    res_2 = task_2(res_1) # Using an iterable data structure as an input parameter\n",
    "    return(res_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f65e82c6",
   "metadata": {},
   "source": [
    "You don't have to pass the entire iterable. You can pass an arbitrary slice of it instead:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "337a1e3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "@ct.lattice\n",
    "def workflow(**params):\n",
    "    res_1 = task_1()\n",
    "    res_2 = task_2(res_1[1:3]) # Using an iterable data structure slice as an input parameter\n",
    "    return(res_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9928a6ca",
   "metadata": {},
   "source": [
    "The key idea is that no work is done on the data outside of the electrons.\n",
    "\n",
    "### See Also\n",
    "\n",
    "[Adding Electrons to Lattices](./add_electron_to_lattice.ipynb)\n",
    "\n",
    "[Looping](./looping.ipynb)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
